<template lang="">
  <div ref="radar" class="radar-echart">
    <!-- 雷达图  图表必须给高和宽度-->
    <!--
        1.准备一个宽高容器
        2.下载引入包
        3.初始化echarts实例 echarts.init
        4.准备数据 option
        5.设置数据 setoption
     -->
  </div>
</template>
<script>
// echarts升级全部倒入
// import * as echarts from 'echarts'
// 改成 按需导入
// 引入 echarts 核心模块，核心模块提供了 echarts 使用必须要的接口。
import * as echarts from 'echarts/core'
// 引入柱状图图表，图表后缀都为 Chart
import { RadarChart } from 'echarts/charts'
// 引入提示框，标题，直角坐标系，数据集，内置数据转换器组件，组件后缀都为 Component
import {
  TitleComponent,
  TooltipComponent,
  LegendComponent
} from 'echarts/components'
// 标签自动布局，全局过渡动画等特性
// import { LabelLayout, UniversalTransition } from 'echarts/features'
// 引入 Canvas 渲染器，注意引入 CanvasRenderer 或者 SVGRenderer 是必须的一步
import { CanvasRenderer } from 'echarts/renderers'

// 注册必须的组件
echarts.use([
  TitleComponent,
  RadarChart,
  LegendComponent,
  TooltipComponent,
  CanvasRenderer
])
export default {
  name: 'Radar',

  mounted() {
    //  3.初始化echarts实例 echarts.init 挂载 到 mounted上面
    const myChart = echarts.init(
      this.$refs.radar
    ) // 得到图表实例
    const option = {
      title: {
        text: 'Basic Radar Chart'
      },
      legend: {
        data: ['Allocated Budget', 'Actual Spending']
      },
      radar: {
        // shape: 'circle',
        indicator: [
          { name: 'Sales', max: 6500 },
          { name: 'Administration', max: 16000 },
          { name: 'Information Technology', max: 30000 },
          { name: 'Customer Support', max: 38000 },
          { name: 'Development', max: 52000 },
          { name: 'Marketing', max: 25000 }
        ]
      },
      series: [
        {
          name: 'Budget vs spending',
          type: 'radar',
          data: [
            {
              value: [4200, 3000, 20000, 35000, 50000, 18000],
              name: 'Allocated Budget'
            },
            {
              value: [5000, 14000, 28000, 26000, 42000, 21000],
              name: 'Actual Spending'
            }
          ]
        }
      ]
    }
    myChart.setOption(option)
  }
}
</script>
<style lang="scss">
.radar-echart {
    width: 500px;
    height: 400px;
}
</style>
